package _15_generics._15_5;

import _15_generics._15_4._05_Generators;
import net.mindview.util.Generator;

import java.util.*;

/**
 * 内部类中使用泛型
 */
public class _01_BankTeller {
    public static void serve(Teller t, Customer c) {
        System.out.println(t + " serves " + c);
    }

    public static void main(String[] args) {
        Random rand = new Random(47);
        Queue<Customer> line = new LinkedList<Customer>();
        _05_Generators.fill(line, Customer.generator, 15);
        List<Teller> tellers = new ArrayList<Teller>();
         _05_Generators.fill(tellers, Teller.generator, 4);
        for(Customer c : line){
            serve(tellers.get(rand.nextInt(tellers.size())), c);
        }
    }
}

class Customer {
    private static long counter = 1;
    private final long id = counter++;

    private Customer() {
    }

    public String toString() {
        return "Customer " + id;
    }

    public static Generator<Customer> generator =
            new Generator<Customer>() {
                @Override
                public Customer next() {
                    return new Customer();
                }
            };

}

class Teller {
    private static long counter = 1;
    private final long id = counter++;

    private Teller() {
    }

    public String toString() {
        return "Teller " + id;
    }

    public static Generator<Teller> generator =
            new Generator<Teller>() {
                public Teller next() {
                    return new Teller();
                }
            };
}
